package com.hl.toolkit.server.chuanglan.demo;

import com.alibaba.fastjson.JSON;
import com.chuanglan.sms.request.SmsSendRequest;
import com.chuanglan.sms.response.SmsSendResponse;
import com.chuanglan.sms.util.ChuangLanSmsUtil;

import java.io.UnsupportedEncodingException;

/**
 * 
 * @author tianyh 
 * @Description:普通短信发送
 */
public class SmsSendChuangLan {

	public static final String charset = "utf-8";
	// 用户平台API账号(非登录账号,示例:N1234567)
	public static String account = "N6476107";
	// 用户平台API密码(非登录密码)
	public static String pswd = "Sl7t6pGvEsc49d";

	public static void main(String[] args) throws UnsupportedEncodingException {

		//普通短信地址
		String smsSingleRequestServerUrl = "http://vsms.253.com/msg/send/json";
		// 短信内容
	    String msg = "你好  你的验证码是123456";
		//手机号码
		String phone = "15239009319";
		//状态报告
		String report= "true";
		
		SmsSendRequest smsSingleRequest = new SmsSendRequest(account, pswd, msg, phone,report);
		
		String requestJson = JSON.toJSONString(smsSingleRequest);
		
		System.out.println("before request string is: " + requestJson);
		
		String response = ChuangLanSmsUtil.sendSmsByPost(smsSingleRequestServerUrl, requestJson);
		
		System.out.println("response after request result is :" + response);
		
		SmsSendResponse smsSingleResponse = JSON.parseObject(response, SmsSendResponse.class);
		
		System.out.println("response  toString is :" + smsSingleResponse); 
		//String or="你好  欢迎来我公司面试 ，地址为 南京东路300号恒基名人大厦20楼2039";
		
		//String chuanglanStr = SmsSendChuangLan.sendChuangLanSms(phone,msg );
		
	
	}
	
	
	public static String sendChuangLanSms(String phone,String msg) throws UnsupportedEncodingException { 
		 String resultStr=""; 
		
		//普通短信地址
		String smsSingleRequestServerUrl = "http://vsms.253.com/msg/send/json";
		// 短信内容
	  //  String msg = "你好,你的验证码是123456";
		//手机号码
		//String phone = "15356675890";
		//状态报告
		String report= "true";
		
		
		SmsSendRequest smsSingleRequest = new SmsSendRequest(account, pswd, msg, phone,report);
		
		String requestJson = JSON.toJSONString(smsSingleRequest);
		
		System.out.println("before request string is: " + requestJson);
		
		String response = ChuangLanSmsUtil.sendSmsByPost(smsSingleRequestServerUrl, requestJson);
		
		System.out.println("response after request result is :" + response);
		
		SmsSendResponse smsSingleResponse = JSON.parseObject(response, SmsSendResponse.class);
		
		System.out.println("response  toString is :" + smsSingleResponse);
		resultStr=response;
		return resultStr; 
	} 
}
